package com.woniu.outpatient.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.woniu.outpatient.service.UserDeptAndDoctorService;

import com.woniu.hospital.domain.Hosptilnews;
import com.woniu.user.domain.Doctor;
import com.woniu.user.vo.DeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniu.outpatient.domain.Checks;
import com.woniu.outpatient.service.IChecksService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 检查名称表Controller
 * 
 * @author wolf-six
 * @date 2023-02-15
 */
@RestController
@RequestMapping("/checks")
public class ChecksController extends BaseController
{
    @Autowired
    private IChecksService checksService;


    @Autowired
    private UserDeptAndDoctorService service;

    /**
     * 查询检查名称表列表
     */
    @RequiresPermissions("outpatient:checks:list")
    @GetMapping("/list")
    public TableDataInfo list(Checks checks)
    {
        startPage();
        List<Checks> list = checksService.selectChecksList(checks);
        for (Checks item:list) {
             String deptName = service.selectById(item.getDeptId()).getDeptName();
             item.setDeptName(deptName);
        }
        return getDataTable(list);
    }

    /**
     * 导出检查名称表列表
     */
    @RequiresPermissions("outpatient:checks:export")
    @Log(title = "检查名称表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Checks checks)
    {
        List<Checks> list = checksService.selectChecksList(checks);
        ExcelUtil<Checks> util = new ExcelUtil<Checks>(Checks.class);
        util.exportExcel(response, list, "检查名称表数据");
    }

    /**
     * 获取检查名称表详细信息
     */
    @RequiresPermissions("outpatient:checks:query")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId)
    {
        return success(checksService.selectChecksByCheckId(checkId));
    }

    /**
     * 新增检查名称表
     */
    @RequiresPermissions("outpatient:checks:add")
    @Log(title = "检查名称表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Checks checks)
    {
        return toAjax(checksService.insertChecks(checks));
    }

    /**
     * 修改检查名称表
     */
    @RequiresPermissions("outpatient:checks:edit")
    @Log(title = "检查名称表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Checks checks)
    {
        return toAjax(checksService.updateChecks(checks));
    }

    /**
     * 删除检查名称表
     */
    @RequiresPermissions("outpatient:checks:remove")
    @Log(title = "检查名称表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds) {
        return toAjax(checksService.deleteChecksByCheckIds(checkIds));
    }
    /**
     *  根据病人id查询检查的所有费用的和
     */

    @GetMapping("/checkAmount/{patientId}")
    public BigDecimal checkAmount(@PathVariable("patientId") Long patientId){
        return checksService.checkAmount(patientId);
    }
}
